package com.ctshk.rpc.order.season.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.enums.IsDeletedCode;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.SnowflakeIdWorker;
import com.ctshk.rpc.order.season.entity.SeasonProductOrderTouristType;
import com.ctshk.rpc.order.season.mapper.SeasonOrderMapper;
import com.ctshk.rpc.order.season.mapper.SeasonProductOrderTouristTypeMapper;
import com.ctshk.rpc.order.season.req.TouristTypeReq;
import com.ctshk.rpc.order.season.service.ISeasonProductOrderTouristTypeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * 套票-订单-旅客类型 服务实现类
 * </p>
 *
 * @author 杨林
 * @since 2021-03-24
 */
@DubboService
public class SeasonProductOrderTouristTypeServiceImpl extends ServiceImpl<SeasonProductOrderTouristTypeMapper, SeasonProductOrderTouristType> implements ISeasonProductOrderTouristTypeService {

    @Autowired
    private SeasonOrderMapper seasonOrderMapper;
    @Autowired
    private SeasonProductOrderTouristTypeMapper touristTypeMapper;
    /* @MethodName: 保存旅客类型
     * @Description: TODO
     * @Param: 
     * @Return: 
     * @Author: 杨林
     * @Date:2021/3/24 20:17
    **/
    @Override
    public void saveTouristType(List<TouristTypeReq> touristTypeReqList,Long userId,Long orderId) {

        LocalDateTime now=LocalDateTime.now();
        List<SeasonProductOrderTouristType> list=touristTypeReqList.stream().map(
                touristReq->{
                    SeasonProductOrderTouristType tourist= EntityUtil.copy(touristReq,SeasonProductOrderTouristType.class);
                    tourist.setSeasonProductId(orderId);
                    tourist.setCreateId(userId);
                    tourist.setGmtCreate(now);
                    tourist.setIsDeleted(IsDeletedCode.NO.getCode());
                    tourist.setId(SnowflakeIdWorker.nextId());
                    return tourist;
                }
        ).collect(Collectors.toList());

        touristTypeMapper.insertBatchSomeColumn(list);
        
    }

    /* @MethodName: 获取旅客数量
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/3/31 14:29
     **/
    @Override
    public Integer getTouristNumber(Long orderId,Integer flag) {
        return seasonOrderMapper.getTouristTypeMapper(orderId,flag);
    }
}
